<template>
  <div id="login">

    <el-card shadow="hover" id="loginCard">
      <div slot="header" class="clearfix" style="text-align: center">
        <span>登录</span>
      </div>
      <el-form :model="loginForm" status-icon :rules="rules" ref="loginForm" label-width="100px">
        <el-form-item label="账号" prop="account">
          <el-input v-model="loginForm.account" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import userApi from "@/api/user";

export default {
  data() {
    var validateAccount = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入账号'));
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      }
    };
    return {
      loginForm: {
        account:'',
        password:'',
      },
      rules: {
        account: [
          { validator: validateAccount, trigger: 'blur' }
        ],
        password: [
          { validator: validatePass, trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    async find() {
      console.log(`登录信息:${this.loginForm}`);
      const {data:res} = await userApi.findAllUser()
      if (res.code === 200) {
        console.log(`登录信息:${this.loginForm}`);
      }
    },
    async login() {
      console.log(`登录信息:${this.loginForm}`);
      const {data:res} = await userApi.login(this.loginForm)
      if (res.code === 200) {
        this.$router.push("/main")
      }
    }
  }
};
</script>

<style>
#login {
  display: flex;
  justify-content: center;
  align-items: center;     /* 垂直居中 */
  height: 100vh;           /* 使容器高度占满视口高度 */
}
#loginCard{
  margin: auto;
  width: 25%;
}
.el-pagination {
  margin-top: 10px;
  text-align: right;
}
</style>
